package com.alibaba.shopping_manager_api.controller;

import com.alibaba.shopping_common.pojo.Category;
import com.alibaba.shopping_common.result.BaseResult;
import com.alibaba.shopping_common.service.CategoryService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName CategoryController
 * @Description TODO
 * @Author Leo
 * @Date 2024/12/11 09:21
 */
@RestController
@RequestMapping("/category")
public class CategoryController {

    @DubboReference
    private CategoryService categoryService;

    /**
     * 分页查询
     * @param page 页码
     * @param size 页面大小
     * @return
     */
    @GetMapping("/search")
    public BaseResult<Page<Category>>search(int page,int size){
        Page<Category> categoryPage = categoryService.search(page, size);
        return BaseResult.OK(categoryPage);
    }

    /**
     * 新增广告数据
     * @param category
     * @return
     */
    @PostMapping("/add")
    public BaseResult<Category> add(@RequestBody Category category){
        categoryService.add(category);
        return BaseResult.OK(category);
    }

    /**
     * 更新广告信息
     * @param category
     * @return
     */
    @PutMapping("/update")
    public BaseResult<Category>update(@RequestBody Category category){
        categoryService.update(category);
        return BaseResult.OK(category);
    }

    /**
     * 更新广告状态
     * @param id
     * @param status
     * @return
     */
    @PutMapping("/updateStatus")
    public BaseResult updateStatus(Long id,Integer status){
        categoryService.updateStatus(id,status);
        return BaseResult.OK();
    }

    /**
     * 根据ID查询广告
     * @param id
     * @return
     */
    @GetMapping("/findById")
    public BaseResult<Category> findById(Long id){
        Category category = categoryService.findById(id);
        return BaseResult.OK(category);
    }

    /**
     * 批量删除广告
     * @param ids
     * @return
     */
    @DeleteMapping("/delete")
    public BaseResult<Long[]>delete(Long[] ids){
        categoryService.delete(ids);
        return BaseResult.OK(ids);
    }


}




